//
//  Settings.m
//  Voxper
//
//  Created by Erphan on 2/7/11.
//  Copyright 2011 Smonte. All rights reserved.
//

#import "Settings.h"
#import "Constants.h"

@implementation Settings

- (NSString *)getUserName {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"]) {
		return (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"];
	}
	return @"";
}

- (void)setUserName:(NSString *)userName {
	[[NSUserDefaults standardUserDefaults] setObject:userName forKey:@"UserName"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)getGSMNumber {
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"GSMNumber"]) {
		return (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:@"GSMNumber"];
	}
	return @"";
}

- (void)setGSMNumber:(NSString *)gsmNumber {
    [[NSUserDefaults standardUserDefaults] setObject:gsmNumber forKey:@"GSMNumber"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}


- (NSString *)getPassword {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"Password"]) {
		return (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:@"Password"];
	}
	return @"";
}

- (void)setPassword:(NSString *)password {
	[[NSUserDefaults standardUserDefaults] setObject:password forKey:@"Password"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)getMyLocation {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"MyLocation"]) {
		return (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:@"MyLocation"];
	}
	return @"";
}

- (void)setMyLocation:(NSString *)country {
	[[NSUserDefaults standardUserDefaults] setObject:country forKey:@"MyLocation"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)getMyLocationCode {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"MyLocationCode"]) {
		return (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:@"MyLocationCode"];
	}
	return @"";
}

- (void)setMyLocationCode:(NSString *)code {
	[[NSUserDefaults standardUserDefaults] setObject:code forKey:@"MyLocationCode"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)getDeviceToken {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"]) {
		return (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"];
	}
	return @"";
	
}

- (void)setDeviceToken:(NSString *)token {
	[[NSUserDefaults standardUserDefaults] setObject:token forKey:@"DeviceToken"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}


- (BOOL)getRegistrationStepCompleted {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"RegistrationStepCompleted"]) {
		return [[NSUserDefaults standardUserDefaults] boolForKey:@"RegistrationStepCompleted"];
	}
	return NO;
}

- (void)setRegistrationStepCompleted:(BOOL)bStepCompleted {
	[[NSUserDefaults standardUserDefaults] setBool:bStepCompleted forKey:@"RegistrationStepCompleted"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (BOOL)getInitialPhoneBookSyncCompleted {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"InitialPhoneBookSyncCompleted"]) {
		return [[NSUserDefaults standardUserDefaults] boolForKey:@"InitialPhoneBookSyncCompleted"];
	}
	return NO;
}
- (void)setInitialPhoneBookSyncCompleted:(BOOL)bSynced {
	[[NSUserDefaults standardUserDefaults] setBool:bSynced forKey:@"InitialPhoneBookSyncCompleted"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (BOOL)getIsPhoneBookAccessGranted {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"IsPhoneBookAccessGranted"]) {
		return [[NSUserDefaults standardUserDefaults] boolForKey:@"IsPhoneBookAccessGranted"];
	}
	return NO;
}
- (void)setIsPhoneBookAccessGranted:(BOOL)bGranted {
	[[NSUserDefaults standardUserDefaults] setBool:bGranted forKey:@"IsPhoneBookAccessGranted"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (int)getContactsGroupSelected {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"ContactsGroupSelected"]) {
		return [[NSUserDefaults standardUserDefaults] integerForKey:@"ContactsGroupSelected"];
	}
	return 0;
}

// this key is managed by uimanager don't set it directly
- (void)setContactsGroupSelected:(int)nSelectedIndex {
	[[NSUserDefaults standardUserDefaults] setInteger:nSelectedIndex forKey:@"ContactsGroupSelected"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (int)getRecentCallsSelected {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"RecentCallsSelected"]) {
		return [[NSUserDefaults standardUserDefaults] integerForKey:@"RecentCallsSelected"];
	}
	return 0;
}

// this key is managed by uimanager don't set it directly
- (void)setRecentCallsSelected:(int)nSelectedIndex {
	[[NSUserDefaults standardUserDefaults] setInteger:nSelectedIndex forKey:@"RecentCallsSelected"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}


- (int)getDefaultTabSelected {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultTabSelected"]) {
		return [[NSUserDefaults standardUserDefaults] integerForKey:@"DefaultTabSelected"];
	}
	return 2;	
}

- (void)setDefaultTabSelected:(int)nSelectedIndex {
	[[NSUserDefaults standardUserDefaults] setInteger:nSelectedIndex forKey:@"DefaultTabSelected"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (int)getLastRegisteredUsersUpdated {
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"LastRegisteredUsersUpdated"]) {
		return [[NSUserDefaults standardUserDefaults] integerForKey:@"LastRegisteredUsersUpdated"];
	}
	return 0;
}

- (void)setLastRegisteredUsersUpdated:(int)nTimeTicks {
    [[NSUserDefaults standardUserDefaults] setInteger:nTimeTicks forKey:@"LastRegisteredUsersUpdated"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)getServerName {
//	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"SipServer"]) {
//		return (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:@"SipServer"];
//	}
	return URL_SIPSERVER;
}

- (void)setServerName:(NSString *)strServerName {
	[[NSUserDefaults standardUserDefaults] setObject:strServerName forKey:@"SipServer"];
	[[NSUserDefaults standardUserDefaults] synchronize];    
}

- (NSString *)getServerPort {
	if ([[NSUserDefaults standardUserDefaults] objectForKey:@"SipPort"]) {
		return (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:@"SipPort"];
	}
	return @"5060";
}

- (void)setServerPort:(NSString *)strServerPort {
	[[NSUserDefaults standardUserDefaults] setObject:strServerPort forKey:@"SipPort"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}

- (BOOL)shouldDisplaySplashView {
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"shouldDisplaySplashView"]) {
		return [[NSUserDefaults standardUserDefaults] boolForKey:@"shouldDisplaySplashView"];
	}
	return YES;
}

- (void)setShouldDisplaySplashView:(BOOL)bShouldDisplay {
    [[NSUserDefaults standardUserDefaults] setBool:bShouldDisplay forKey:@"shouldDisplaySplashView"];
	[[NSUserDefaults standardUserDefaults] synchronize];
}


@end
